﻿
@page "/_Admin/DicDef/Details"
@using nERP.ViewModel._Admin.DicDefVMs
@using nERP.Model._Admin
@using System.ComponentModel.DataAnnotations
@inherits BasePage

<ValidateForm @ref="vform" Model="@Model" OnValidSubmit="@Submit" >
  <Row ItemsPerRow="ItemsPerRow.One" RowType="RowType.Normal">
    <Display @bind-Value="@Model.Entity.DicName"  ShowLabel="true" IsDisabled="true"/>

    <Table TItem="DicField"
              IsPagination="false" 
              IsStriped="true" IsBordered="true" IsMultipleSelect="false" @bind-Items="@DicFieldDicDefList2"
              ShowToolbar="false" ShowExtendButtons="false" ShowSkeleton="true">
      <TableColumns>
        <TableColumn @bind-Field="@context.DicFieldName" Text="@WtmBlazor.Localizer["Page.键"]" />
        <TableColumn @bind-Field="@context.DicFieldDes" Text="@WtmBlazor.Localizer["Page.值"]" />
        <TableColumn @bind-Field="@context.Order" Text="@WtmBlazor.Localizer["Page.排序"]" />
      </TableColumns>

    </Table>

  </Row>

  <div class="modal-footer table-modal-footer">
    <Button OnClick="OnClose" Text="@WtmBlazor.Localizer["Sys.Close"]"/>
  </div>

</ValidateForm>



@code {
    [Parameter]
    public string id { get; set; }
    [Parameter]
    public string[] ids { get; set; }
    private DicDefVM Model = new DicDefVM();
    private ValidateForm vform { get; set; }
    private async Task Submit(EditContext context)
    {
                        
        
        await PostsForm(vform, "/api/_Admin/DicDef/Edit", (s) => "Sys.OprationSuccess");
    }
    public void OnClose()
    {
        CloseDialog();
    }
    
    private List<SelectedItem> AllDicDefs = new List<SelectedItem>();
    private IEnumerable<DicField> DicFieldDicDefList2 { get; set; } = new List<DicField>();
    protected override async Task OnInitializedAsync()
    {
        
        
        AllDicDefs = await WtmBlazor.Api.CallItemsApi("/api/_Admin/DicField/GetDicDefs");
        AllDicDefs.Insert(0, new SelectedItem { Text = WtmBlazor.Localizer["Sys.PleaseSelect"],Value = "" });
        if (id != "")
        {
            var rv = await WtmBlazor.Api.CallAPI<DicDefVM>($"/api/_Admin/DicDef/{id}");
            Model = rv.Data;
        }
        DicFieldDicDefList2 = Model.Entity.DicField_DicDef;

        await base.OnInitializedAsync();
    }
}
